﻿using Appliaction.AppServices.Inv;
using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using EFCore.Repositorys.Inv;
using Microsoft.AspNetCore.Mvc;
using static StackExchange.Redis.Role;
using static System.Runtime.CompilerServices.RuntimeHelpers;

namespace API.Controllers.Inv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Inv_QtyController : Controller
    {

        private readonly IMapper _mapper;
        private readonly IInv_QtyServices _inv_Qtyservices;

        public Inv_QtyController(IInv_QtyServices _inv_Qtyservices, IMapper mapper)
        {
            this._inv_Qtyservices = _inv_Qtyservices;
            _mapper = mapper;
        }


        /// <summary>
        /// 根据编号查询盘点信息
        /// </summary>
        /// <param name="qty_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> Inv_Qty_SelectCode(string qty_code)
        {
            var result = await _inv_Qtyservices.Inv_Qty_SelectCode(qty_code);
            return new JsonResult(result);
        }
        /// <summary>
        /// 查询总数
        /// </summary>
        /// <param name="qty_code"></param>
        /// <param name="qty_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> Inv_Qty_selectCount(string ? qty_code, string ? qty_type,string? proName)
        {
            return _inv_Qtyservices.Inv_Qty_selectCount(qty_code, qty_type, proName);
        }
        /// <summary>
        /// 根据库存盘点查询明细
        /// </summary>
        /// <param name="trf_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<JsonResult> Inv_Qty_SelectDetail(string qty_code)
        {
            var result = await _inv_Qtyservices.Inv_Qty_SelectDetail(qty_code);
            return new JsonResult(result);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="qty_code"></param>
        /// <param name="qty_type"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult Inv_Qty_selectFY(string ? qty_code, string ? qty_type, int currentPage, int pageSize, string? proName)
        {
            return new JsonResult(_inv_Qtyservices.Inv_Qty_selectFY(qty_code, qty_type, currentPage, pageSize,proName)); 
        }

        /// <summary>
        /// 修改审核状态--盘点
        /// </summary>
        /// <param name="inv_QtyUpdateDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_qty_examineUpdate(Inv_QtyUpdateDto inv_QtyUpdateDto)
        {
           return _inv_Qtyservices.Inv_qty_examineUpdate(inv_QtyUpdateDto);
        }


        /// <summary>
        /// 删除盘点单
        /// </summary>
        /// <param name="qty_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_Qty_delete(int qty_id)
        {
            return _inv_Qtyservices.Inv_Qty_delete(qty_id);
        }

        /// <summary>
        /// 添加盘点单
        /// </summary>
        /// <param name="inv_QtyAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> Inv_trf_Insert(Inv_QtyAddDto inv_QtyAddDto)
        {
         return _inv_Qtyservices.Inv_trf_Insert(inv_QtyAddDto);
        }


        /// <summary>
        /// 添加明细表--盘点   
        /// </summary>
        /// <param name="inv_proddtiList"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<IActionResult> inv_proddti_Insert(List<Inv_Proddti_AddDto> inv_proddtiList)
        {
          int result=await _inv_Qtyservices.inv_proddti_Insert(inv_proddtiList);
          return Ok(result);
        }


        /// <summary>
        /// 根据盘点单号查询盘点单id
        /// </summary>
        /// <param name="Qty_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> inv_Qty_id(string Qty_code)
        {
           return _inv_Qtyservices.inv_Qty_id(Qty_code);
        }


        /// <summary>
        ///  修改盘点单和详情单
        /// </summary>
        /// <param name="inv_QtyUpdateMerageDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> Inv_Qty_Update([FromBody] Inv_QtyUpdateMerageDto inv_QtyUpdateMerageDtoS)
        {
            if (inv_QtyUpdateMerageDtoS == null) { 
            
            return new JsonResult(new { code = 0, msg = "参数为空" });
            }
           return new JsonResult(await _inv_Qtyservices.Inv_Qty_Update(inv_QtyUpdateMerageDtoS));
        }


        /// <summary>
        /// 其他入库单查询盘点单
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public  JsonResult Inv_Qty_MainSelect(string ? code, int currentPage, int pageSize)
        {

            return new JsonResult(_inv_Qtyservices.Inv_Qty_MainSelect(code, currentPage, pageSize));
        }
        /// <summary>
        /// 其他入库单查询盘点单--其他入库单
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Inv_Qty_MainSelect_Count(string ? code)
        {
            return _inv_Qtyservices.Inv_Qty_MainSelect_Count(code);
        }

        /// <summary>
        /// 根据编码查询仓库盘点详情信息--其他入库单
        /// </summary>
        /// <param name="trf_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Inv_Qty_SelectMainDetail(string qty_code)
        {

            var result = await _inv_Qtyservices.Inv_Qty_SelectMainDetail(qty_code);
            return new JsonResult(result);
        }


        /// <summary>
        /// 盘亏出库--其他出库单
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Inv_Qty_Maisbhg_Select(string ? code, int currentPage, int pageSize)
        {

            return new JsonResult(_inv_Qtyservices.Inv_Qty_Maisbhg_Select(code, currentPage, pageSize));
        }

        /// <summary>
        /// 其他入库单查询盘点单--其他出库单
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Inv_Qty_Maisbhg_Select_Count(string ? code)
        {

            return _inv_Qtyservices.Inv_Qty_Maisbhg_Select_Count(code);
        }

        /// <summary>
        /// 根据编码查询仓库盘点详情信息--其他出库单
        /// </summary>
        /// <param name="trf_code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Inv_Qty_SelectMainbhgDetail(string ? qty_code)
        {

            var result = await _inv_Qtyservices.Inv_Qty_SelectMainbhgDetail(qty_code);
            return new JsonResult(result);
        }




        /// <summary>
        /// 盘点详情修改状态--其他入库单完毕之后
        /// </summary>
        /// <param name="inv__proddtiUpdateztDtos"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public  async Task<IActionResult> Inv_Qty_Update_zt(List<Inv__proddtiUpdateztDto> inv__proddtiUpdateztDtos)
        {
            int result = await _inv_Qtyservices.Inv_Qty_Update_zt(inv__proddtiUpdateztDtos);
            return Ok(new { succes = true, count = result });
        }


        /// <summary>
        /// 其他出库单审核完毕之后,修改盘点单的qty_store_bhg这个字段为1
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> Inv_qty_update_qty_store_bhg(string code)
        {

           return _inv_Qtyservices.Inv_qty_update_qty_store_bhg(code);
        }

    }
}
